package main

import (
	"fmt"
	"reflect"
)

func main() {
	// slices are like arrays, but can be resizeds
	s := make([]string, 3)
	fmt.Println("emp: ", s)
	fmt.Println("len: ", len(s))
	fmt.Println("cap: ", cap(s))

	s[0] = "a"
	s[1] = "b"
	s[2] = "c"
	fmt.Println("set: ", s)
	fmt.Println("get: ", s[2])
	fmt.Println("len: ", len(s))
	fmt.Println("cap: ", cap(s))

	s = append(s, "d")
	fmt.Println("apd: ", s)

	s = append(s, "e", "f")
	fmt.Println("apd: ", s)

	c := make([]string, len(s))
	copy(c, s)
	fmt.Println("cpy: ", c)

	l := s[2:5]
	fmt.Println("sl1: ", l)

	l = s[:5]
	fmt.Println("sl2: ", l)

	l = s[2:]
	fmt.Println("sl3: ", l)
	//  这里没有指定长度，所以是slice
	t := []string{"g", "h", "i"}
	fmt.Println("dcl: ", t)
	fmt.Println("len: ", len(t))
	fmt.Println("cap: ", cap(t))

	fmt.Printf("The type of t: %T\n", t)
	switch i := interface{}(t).(type) {
	case []string:
		fmt.Println("The type of t is []string")
	case []int:
		fmt.Println("The type of t is []int")
	default:
		fmt.Printf("Unknown type: %T\n", i)
	}

	fmt.Println("The type of t is : ", reflect.TypeOf(t))

	twoD := make([][]int, 3)
	for i := 0; i < 3; i++ {
		innerLen := i + 1
		twoD[i] = make([]int, innerLen)
		for j := 0; j < innerLen; j++ {
			twoD[i][j] = i + j
		}
	}

	fmt.Println("2d: ", twoD)
	fmt.Println("2d's len: ", len(twoD))
	fmt.Println("2d's cap: ", cap(twoD))
	fmt.Printf("2d's type: %T\n", twoD)

	fmt.Println("2d[0]'s len: ", len(twoD[0]))
	fmt.Println("2d[0]'s cap: ", cap(twoD[0]))
	fmt.Printf("2d[0]'s type: %T\n", twoD[0])
	fmt.Println("2d[1]'s len: ", len(twoD[1]))
	fmt.Println("2d[1]'s cap: ", cap(twoD[1]))
	fmt.Printf("2d[1]'s type: %T\n", twoD[1])
	fmt.Println("2d[2]'s len: ", len(twoD[2]))
	fmt.Println("2d[2]'s cap: ", cap(twoD[2]))
	fmt.Printf("2d[2]'s type: %T\n", twoD[2])

}
